/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pa165.pneu.pneuservisbackend.services;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pa165.pneu.pneuservisbackend.dao.OrderPneuDAO;
import pa165.pneu.pneuservisbackend.entiies.OrderPneu;
import pa165.pneu.pneuservisbackend.to.CustomerTO;
import pa165.pneu.pneuservisbackend.to.OrderPneuTO;

/**
 *
 * @author Martin Tarasovic
 */
@Service
public class OrderPneuServiceImpl implements OrderPneuService {

    @Autowired
    private OrderPneuDAO orderPneuDAO;
    
    @Transactional
    @Override
    public void createOrder(OrderPneuTO orderPneu) {
        orderPneuDAO.createOrder(orderPneu.toOrderPneu());
    }

    @Transactional
    @Override
    public OrderPneuTO getOrder(Long id) {
        return new OrderPneuTO(orderPneuDAO.getOrder(id));
    }

    @Transactional
    @Override
    public void updateOrder(OrderPneuTO orderPneu) {
        orderPneuDAO.updateOrder(orderPneu.toOrderPneu());
    }

    @Transactional
    @Override
    public void removeOrder(OrderPneuTO orderPneu) {
        orderPneuDAO.removeOrder(orderPneu.toOrderPneu());
    }

    @Transactional
    @Override
    public List<OrderPneuTO> getAllOrders() {
        List<OrderPneuTO> list = new ArrayList();
        for(OrderPneu o : orderPneuDAO.getAllOrders()) {
            list.add(new OrderPneuTO(o));
        }
        return list;
    }

    @Transactional
    @Override
    public List<OrderPneuTO> getOrdersByCustomer(CustomerTO customer) {
        List<OrderPneuTO> list = new ArrayList();
        for(OrderPneu o : orderPneuDAO.getOrdersByCustomer(customer.toCustomer())) {
            list.add(new OrderPneuTO(o));
        }
        return list;
    }
}